/*
 * @Author: chentao 294446993@qq.com
 * @Date: 2022-12-05 11:25:12
 * @LastEditors: chentao 294446993@qq.com
 * @LastEditTime: 2022-12-30 13:56:56
 * @FilePath: \desktop\frontend\src\store\modules\dialogue.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ADD_GROUP_MANAGER_LIST, GROUP_MANAGER_FUNC, MANAGER_LIST, PANEL_HEADER_LIST_VISIBLE, DIALOG_ADD_FRIEND_VISIBLE,DIALOG_MSG_USER_DETAIL_VISIBLE } from "@/store/actiontypes";
export default {
  state: {
    // 对话来源[1:私聊;2:群聊]
    talk_type: 0,

    // 接收者ID
    receiver_id: 0,

    is_robot: 0,

    // 聊天记录
    records: [],

    // 对话索引（聊天对话的唯一索引）
    index_name: null,

    //群组弹窗之间相关控制
    dialogGroupManagerVisible: false, //群组弹窗开关

    //控制添加管理员弹窗 展示与否
    dialogGroupManagerListVisible: false,//

    //这个是控制PanelHeader组件下的chatSelectionBox 弹窗组件的开关
    panelHeaderListSelectVisible: false,
    //群组管理员列表
    groupManagerList: [
      {
        "img": "https://aitd-block-image-public.s3.ap-southeast-1.amazonaws.com/social_finance/user/avatar/ff5675ee-7309-4f28-885f-cad9f1091a8f.jpg",
        "notes": "",
        "gender": 1,
        "headImg": "",
        "signature": "一个大神般的人",
        "isLeader": true,
        "groupUserTagImg": "https://aitd-block-image-public.s3.ap-southeast-1.amazonaws.com/img/group_own.png",
        "groupId": 19036,
        "gnickname": "",
        "userSn": 3791154,
        "userId": "5a375b8b1eec4492b2081a850db3b617",
        "nationality": "65,新加坡",
        "muteStatus": false,
        "nickname": "一点",
        "labelImg": "",
        "isManager": false,
        "isFriend": true
      },
      {
        "img": "https://aitd-block-1304418020.cos.ap-guangzhou.myqcloud.com/social_finance/user/image/ios/751C15F0-FFD5-4FDE-845B-51871CB7B069.jpeg",
        "notes": "产品经理-一流",
        "gender": 1,
        "headImg": "",
        "signature": "我是塔奇克马",
        "isLeader": false,
        "groupUserTagImg": "",
        "groupId": 19036,
        "gnickname": "",
        "userSn": 1573311,
        "userId": "b4c6edf5dcf9488fa9b2e346eff02474",
        "nationality": "852,中国香港",
        "muteStatus": false,
        "nickname": "Tqkm~bato",
        "labelImg": "",
        "isManager": false,
        "isFriend": true
      },
      {
        "img": "https://aitd-block-1304418020.cos.ap-guangzhou.myqcloud.com/social_finance/user/image/ios/8DCB2605-B2BB-44F9-A6F8-D1E407ACA880.jpeg",
        "notes": "",
        "gender": 1,
        "headImg": "",
        "isLeader": false,
        "groupUserTagImg": "",
        "groupId": 19036,
        "gnickname": "",
        "userSn": 3793355,
        "userId": "b6be12d4999947a2aaa19c6f55ade71d",
        "nationality": "新加坡",
        "muteStatus": false,
        "nickname": "          小姐姐。  ",
        "labelImg": "",
        "isManager": false,
        "isFriend": false
      }
    ],//群管理员列表集合
  },
  mutations: {
    //展示添加好友弹窗
    [DIALOG_ADD_FRIEND_VISIBLE](state, { dialogAddFriendVisible }) {
      state.dialogAddFriendVisible = dialogAddFriendVisible
    },
    //展示用户详情弹窗
    [DIALOG_MSG_USER_DETAIL_VISIBLE](state, { dialogMsgUserDetailVisible }) {
      state.dialogMsgUserDetailVisible = dialogMsgUserDetailVisible
    },
    //外部控制 panelHeaderListSelectVisible
    [PANEL_HEADER_LIST_VISIBLE](state, { panelHeaderListSelectVisible }) {
      state.panelHeaderListSelectVisible = panelHeaderListSelectVisible
    },
    //群组介绍 弹窗 控制
    [GROUP_MANAGER_FUNC](state, payload) {
      state.dialogGroupManagerVisible = payload.dialogGroupManagerVisible
    },
    //添加管理员列表弹窗展示
    [ADD_GROUP_MANAGER_LIST](state, payload) {
      // console.log("修改前端listVisible",state.dialogGroupManagerListVisible)
      state.dialogGroupManagerListVisible = payload.dialogGroupManagerListVisible;
      //console.log("visible",state.dialogGroupManagerListVisible)
    },
    //更新群组管理员列表
    [MANAGER_LIST](state, { groupManagerList }) {
      state.groupManagerList = groupManagerList
    },
    // 更新对话
    UPDATE_DIALOGUE_MESSAGE(state, resource) {
      state.records = [];
      state.talk_type = parseInt(resource.talk_type);
      state.receiver_id = parseInt(resource.receiver_id);
      state.is_robot = parseInt(resource.is_robot);

      if (state.talk_type === 0 || state.receiver_id === 0) {
        state.index_name = null;
      } else {
        state.index_name = resource.talk_type + "_" + resource.receiver_id;
      }
    },

    // 数组头部压入对话记录
    UNSHIFT_DIALOGUE(state, records) {
      state.records.unshift(...records);
    },

    // 推送对话记录
    PUSH_DIALOGUE(state, record) {
      state.records.push(record);
    },

    // 更新对话记录
    UPDATE_DIALOGUE(state, resource) {
      for (const iterator of state.records) {
        if (iterator.id === resource.id) {
          Object.assign(iterator, resource);
          break;
        }
      }
    },

    // 删除对话记录
    DELETE_DIALOGUE(state, index) {
      state.records.splice(index, 1);
    },

    BATCH_DELETE_DIALOGUE(state, ids) {
      ids.forEach((record_id) => {
        let index = state.records.findIndex((item) => item.id == record_id);
        if (index >= 0) state.records.splice(index, 1);
      });
    },

    // 数组头部压入对话记录
    SET_DIALOGUE(state, records) {
      state.records = records;
    },
  },
};
